package com.ruoyi.supermarket.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.supermarket.domain.Vo.ShCx;
import com.ruoyi.supermarket.domain.Vo.ShXs;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supermarket.domain.Sale;
import com.ruoyi.supermarket.service.ISaleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售汇总Controller
 * 
 * @author ruoyi
 * @date 2024-05-28
 */
@RestController
@RequestMapping("/supermarket/sale")
public class SaleController extends BaseController
{
    @Autowired
    private ISaleService saleService;

    /**
     * 查询销售汇总列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sale sale)
    {
        startPage();
        List<Sale> list = saleService.selectSaleList(sale);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('supermarket:sale:list')")
    @GetMapping("/cSlist")
    public TableDataInfo cSlist(Sale sale)
    {
        startPage();
        List<Sale> list = saleService.selectSaleListCs(sale);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('supermarket:sale:list')")
    @GetMapping("/listTwo")
    public TableDataInfo listTwo(Sale sale)
    {
        startPage();
        List<Sale> list = saleService.selectSaleListTwo(sale);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('supermarket:sale:list')")
    @GetMapping("/listThree")
    public TableDataInfo listThree(Sale sale)
    {
        startPage();
        List<Sale> list = saleService.selectSaleListThree(sale);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('supermarket:sale:list')")
    @GetMapping("/listZf")
    public TableDataInfo listZf(Sale sale)
    {
        startPage();
        List<Sale> list = saleService.selectSaleListZf(sale);
        return getDataTable(list);
    }


    /**
     * 导出销售汇总列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:sale:export')")
    @Log(title = "销售汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sale sale)
    {
        List<Sale> list = saleService.selectSaleList(sale);
        ExcelUtil<Sale> util = new ExcelUtil<Sale>(Sale.class);
        util.exportExcel(response, list, "销售汇总数据");
    }

    /**
     * 获取销售汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:sale:query')")
    @GetMapping(value = "/{saleId}")
    public AjaxResult getInfo(@PathVariable("saleId") Long saleId)
    {
        return success(saleService.selectSaleBySaleId(saleId));
    }

    /**
     * 新增销售汇总
     */
    @PreAuthorize("@ss.hasPermi('supermarket:sale:add')")
    @Log(title = "销售汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sale sale)
    {
        return toAjax(saleService.insertSale(sale));
    }

    /**
     * 修改销售汇总
     */
    @PreAuthorize("@ss.hasPermi('supermarket:sale:edit')")
    @Log(title = "销售汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sale sale)
    {
        return toAjax(saleService.updateSale(sale));
    }

    /**
     * 删除销售汇总
     */
    @PreAuthorize("@ss.hasPermi('supermarket:sale:remove')")
    @Log(title = "销售汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{saleIds}")
    public AjaxResult remove(@PathVariable Long[] saleIds)
    {
        return toAjax(saleService.deleteSaleBySaleIds(saleIds));
    }

    //审核
    @PostMapping("/audit")
    @PreAuthorize("@ss.hasPermi('supermarket:sale:audit')")
    public AjaxResult audit(@RequestBody ShXs shXs)
    {
        return saleService.audit(shXs);
    }



    @GetMapping("/inStore/{saleId}")
    @PreAuthorize("@ss.hasPermi('supermarket:sale:inStore')")
    public AjaxResult inStore(@PathVariable Long saleId)
    {
        return saleService.inStore(saleId);
    }


    @GetMapping("/outStore/{saleId}")
    @PreAuthorize("@ss.hasPermi('supermarket:sale:outStore')")
    public AjaxResult outStore(@PathVariable Long saleId)
    {
        return saleService.outStore(saleId);
    }


    /**
     * 收款单
     */
    @PreAuthorize("@ss.hasPermi('supermarket:sale:pay')")
    @GetMapping("/pay/{ids}")
    public AjaxResult pay(@PathVariable List<Long> ids){
        return saleService.pay(ids);
    }


    /**
     * 反审核
     * @param sale
     * @return
     */
    @PutMapping("/fsh")
    @PreAuthorize("@ss.hasPermi('supermarket:sale:fsh')")
    public AjaxResult fsh(@RequestBody Sale sale)
    {
        return toAjax(saleService.updatefsh(sale));
    }


    @GetMapping("/zfSale/{saleId}")
    @PreAuthorize("@ss.hasPermi('supermarket:sale:zfSale')")
    public AjaxResult pay(@PathVariable Long saleId){
        return saleService.zfSale(saleId);
    }


}
